<template>
    <a-card :bordered="false">
        <div class="table-operator">
            <a-button shape="round" size="small" type="primary" icon="plus" @click="handleEdit({},'templateForm','新增')">添加</a-button>
        </div>

        <LTable
            ref="flowTemplateList"
            size="middle"
            rowKey="keyId"
            :formAttributes="formAttributes"
            :initOrder="initOrder"
            :initQuery="[{field:'systemNo',val:defaultSettings.systemNo}]"
            :columns="columns"
            axiosUrl="/SysFlowTemplateController/page"
            :showPagination="true"
            :showQueryForm="true"
        >
            <span slot="action" slot-scope="text, record">
            <a @click="handleEdit(record,'templateForm',record.roleName)">编辑</a>
            <a-divider type="vertical" />
            <a @click="delpoy(record)">部署</a>
            <a-divider type="vertical" />
            <a @click="clearHis(record)">清理历史</a>
            <a-divider type="vertical" />
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete({keyId:record.keyId,templateNo:record.templateNo},'/SysFlowTemplateController/del','flowTemplateList')">
                    <a>删除</a>
                </a-popconfirm>
            </span> 
        </LTable>

        <templateForm ref="templateForm" @close="refresh('flowTemplateList')" @ok="refresh('flowTemplateList')"></templateForm>
    </a-card>
</template>

<script>
import LTable from '@/components/lt/LTable'
import {SysMixin} from '@/mixins/SysMixin'
import defaultSettings from '@/config/defaultSettings'
import templateForm from './templateForm'
import request from '@/utils/request'

export default {
    name:'flowTemplateList',
    components:{
       LTable,templateForm
    },
    mixins:[SysMixin],
    data(){
        return{
            defaultSettings,
            formAttributes:[
                {field:'templateName',label:'模版名称',component:'input',condition:'like'},
            ],
            initOrder:[{field:'templateVersion',val:'desc'}],
            columns:[
                {
                    title: '序号',
                    dataIndex: '',
                    key:'rowIndex',
                    width:60,
                    align:"center",
                    customRender:function (t,r,index) {
                      return parseInt(index)+1;
                    }
                },
                
                {
                    title: '模版编号',
                    dataIndex: 'templateNo'
                },
                {
                    title: '模版名称',
                    dataIndex: 'templateName'
                    
                },
                {
                    title: '部署版本',
                    dataIndex: 'templateVersion',
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    width: '230px',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            
        }
    },
    created(){
       
    },
    methods:{
        //部署
        delpoy(record){
            var that = this;
            request.get('/SysFlowTemplateController/deploy',{params:{keyId:record.keyId}}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('flowTemplateList');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        //清理历史
        clearHis(record){
            var that = this;
            request.get('/SysFlowTemplateController/clearHis',{params:{keyId:record.keyId}}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('flowTemplateList');
                } else {
                    that.$message.warning(res.message);
                }
            })
        }
        
    }
}
</script>